package com.mk;

import com.mj.dao.BookDao;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:applicationContext.xml"})//单元测试
public class Demo {
    //@Autowired
    //protected BookDao bookDao;//如果有别的也想用，只要在自动装配一个就行了，在测试类里面直接用就好了
    @Resource(name = "ab")//如果后面不写name的话，这个是默认根据类型找的
    private BookDao bookDao;
    @Autowired
    private SqlSession session;
    @Test
    public void ts(){
        System.out.println(session);
    }
    @Test
    public void tt(){
        System.out.println(bookDao.queryById(4));//有了上面那两行代码，每次就不需要再获取映射文件了
    }
}
